home *** CD-ROM | disk | FTP | other *** search
- Path: erich.triumf.ca!bennett
- From: bennett@erich.triumf.ca (P.Bennett)
- Newsgroups: comp.lang.c
- Subject: Re: File Open Problem - Please provide clues
- Date: 6 Apr 1996 09:20 PST
- Organization: TRIUMF: Tri-University Meson Facility
- Distribution: world
- Message-ID: <6APR199609203190@erich.triumf.ca>
- References: <4jkq8h$1it6@useneta1.news.prodigy.com> <xZaQmMD12aUz1@andi.art-line.de>
- NNTP-Posting-Host: ftp.triumf.ca
- News-Software: VAX/VMS VNEWS 1.50
-
- In article <xZaQmMD12aUz1@andi.art-line.de>, andi@art-line.de (Andreas Winkelmann) writes...
- >Hi Steve.
- >
- >> Hi I'm having problems with opening files which are named
- >> after simple numbers:
-
- >> I get mismatched type errors when using FOPEN:
- >> int num;
- >> filepointer = FOPEN(num,"r"); or
- >> filepointer = FOPEN("num","r");
- >
- >fopen() accepts as the first argument only a stringpointer. You
- >have to convert the number in a string.
- >
- >char buffer[21];
- >FILE *fp;
- >int num;
- >
- >sprintf( (char*)&buffer,"%ld.txt",num);
- >fp = fopen( (char*)&buffer, "r" );
-
- What is the (char*) cast for? 'buffer' is already a char*. The name of an
- array acts as a pointer to the first element when used as a function argument.
-
- Also, "%ld" is used to print longs - you use "%d" to print an int.
-
- So the above should be:
- sprintf(buffer, "%d.txt", num);
- fp = fopen(buffer, "r");
-
- Peter Bennett VE7CEI | Vessels shall be deemed to be in sight
- Internet: bennett@triumf.ca | of one another only when one can be
- Packet: ve7cei@ve7kit.#vanc.bc.ca | observed visually from the other
- TRIUMF, Vancouver, B.C., Canada | ColRegs 3(k)
- GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
- or: ftp://ftp-i2.informatik.rwth-aachen.de/pub/arnd/GPS/peter/index.html
-
-
-
-
-
-
-
-
-